#!/bin/sh

HOME_DIR=/home
MUSIC_BASE_DIR=/home/lancerx/data_extra/musics

if [ $# -lt 2 ]; then
	echo "Usage: $0 m3u_file export_dir"
	exit 1
fi

if [ ! -e $1 ]; then
	echo "File \`$1' not exists"
	exit 1
fi

if [ -e $2 ]; then
	echo "Output dir \`$2' already exists"
	exit 1
fi

mkdir "$2" || exit 2

SAVEIFS="${IFS}"
export IFS=$(echo -ne "\n\b")
for f in $(grep "^[^#]" $1) ;
do
	fname=$(basename $f)
	echo $fname
	while [ -e "$2/$fname" ]; do
		fname="1.$fname"
	done
	cp "$HOME_DIR/$f" "$2/$fname"
done

export IFS="${SAVEIFS}"
